﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BEX.RuleMonitor
{
    public class SafeQueue
    {
        private Queue<AlertRule> _q = new Queue<AlertRule>();
        private readonly object _qLock = new object();

        public void AddToQueue(AlertRule toAdd)
        {
            lock (_qLock)
            {
                _q.Enqueue(toAdd);
            }
        }

        public AlertRule GetNext()
        {
            AlertRule res = null;

            lock (_qLock)
            {
                if (_q.Count > 0)
                {
                    res = _q.Dequeue();
                }
            }

            return res;
        }

        public int QueueCount
        {
            get
            {
                var res = -1;

                lock (_qLock)
                {
                    res = _q.Count;
                }

                return res;
            }
        }
    }
}
